package com.projectimport.dao;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.projectimport.model.EnResources;
@Transactional
@Repository
public interface EnResourcesDao extends CrudRepository<EnResources, String>{
	@Query(nativeQuery=true,value="select resources_name from en_resources where xpmobs_sid="
			+ "(select proj_sid from en_plan_version_cj where plan_version_sid=?1)")
	public List<String> findByplanVersionSid(String planVersionSid);
	@Query(nativeQuery=true,value="SELECT  CASE WHEN ISNULL(MAX(RIGHT(RESOURCES_CODE, 4)), '') = '' THEN '1000' "
			+ "ELSE MAX(RIGHT(RESOURCES_CODE, 4)) "
			+ " END AS max_code"
			+ " FROM    dbo.EN_RESOURCES "
			+ " WHERE   xpmobs_sid = ( SELECT   proj_sid"
			+ " FROM     dbo.EN_PLAN_VERSION_CJ"
			+ " WHERE    plan_version_sid =?1"
			+ "  )"
			+ " AND PATINDEX('R[1-9][1-9][1-9][1-9]', RESOURCES_CODE) <> -1")
	public String getMaxCode(String planVersionSid);
}
